package com.minicat.server;

import java.io.IOException;

public class HttpServlet implements Servlet {

    public void doGet(Request request,Response response) throws IOException {
        String content = "<h1> HttpServlet GET";
        response.output(HttpProtocolUtil.getHttp200(content.getBytes().length)+content);
    }

    public void doPost(Request request,Response response) throws IOException {
        String content = "<h1> HttpServlet POST";
        response.output(HttpProtocolUtil.getHttp200(content.getBytes().length)+content);
    }

    @Override
    public void init() {
        System.out.println("HttpServlet init()");
    }

    @Override
    public void destory() {
        System.out.println("HttpServlet destory()");
    }

    @Override
    public void service(Request request, Response response) throws Exception {
        if ("GET".equalsIgnoreCase(request.getMethod())){
            doGet(request,response);
        }else{
            doPost(request,response);
        }
    }
}
